<!DOCTYPE html>
<html> 
<head> 
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">  
    <title>组织机构管理</title> 
    <link rel="shortcut icon" href="favicon.ico">
	<#import "/common/import.ftl" as import>
    <@import.tableManagerImportCss/>
    <link href="${WEB_PATH}/resources/css/plugins/treeview/bootstrap-treeview.css" rel="stylesheet">
    <link href="${WEB_PATH}/resources/css/plugins/jsTree/style.min.css" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        

        <!-- Panel Other -->
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>组织机构</h5>
                <div class="ibox-tools"> 
                </div>
            </div>
            <div class="ibox-content">
                <div class="row row-lg">  
                    <div class="col-sm-12">
                        <!-- Example Events -->
                        <div class="example-wrap"> 
                            <div class="example"> 
                            	<div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
                                    <button type="button" class="btn btn-outline btn-default" data-toggle="modal" id="addMeun" data-target="#userModal">
                                        <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>&nbsp;&nbsp;新增
                                    </button>
                                    <button type="button" class="btn btn-outline btn-default" id="editMeun" >
                                        <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>&nbsp;&nbsp;修改
                                    </button>
                                    <button type="button" class="btn btn-outline btn-default" id="delMeun">
                                        <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>&nbsp;&nbsp;删除
                                    </button>
                                </div>
						            <div class="ibox float-e-margins" style="margin-top:15px;">
						                <div class="ibox-content">
						                    <div id="using_json" class="test"></div>
						                </div>
						            </div>
                            </div>
                        </div>
                        <!-- End Example Events -->
                    </div>
                </div>
            </div>
        </div>
        <!-- End Panel Other -->
    </div>
    <div id="win_add"></div>
	<div id="win_edit"></div>
	
    <@import.tableManagerImportScript/>
    <script src="${WEB_PATH}/resources/js/demo/treeview-demo.min.js"></script>
    <script src="${WEB_PATH}/resources/js/plugins/jsTree/jstree.min.js"></script>
<script>
	 $(document).ready(function() {
	 
	 	$('.dropdown-menu a.jstree-anchor').click(function(e) {
	 		alert("aaa");
		    e.stopPropagation();
		});

	 	var menuId = "";
	 	var leavaId = "";
	 	
	 	 $('#using_json').jstree({
            'core': {
               'themes':{
			            "icons" : false
			        },
                    'data': ${json}
            }
	        }).bind('changed.jstree', function(event,data) {
	        		console.log(data.node.id);
	                menuId = data.node.id;  //获取点击ID
	                leavaId = $(event.target).parents('li').attr('aria-level');  //获取点击ID
	                if(data.node.parent != "#") {
	               	//	$("#delMeun").removeAttr("disabled");
	                }else{
	                //	$("#delMeun").attr("disabled","disabled");
	                }
	        }).bind('dblclick.jstree', function(event) {
		}).bind('click.jstree', function(event){
			 event.stopPropagation();
		});
       
		//加载添加页面
        $('#addMeun').click(function(){
        		layer.open({
			      type: 2,
			      title: '<span style="color: #ed5565">新增机构<span>',
			      shadeClose: false, 
			      shade: 0.3,
			      maxmin: false, //开启最大化最小化按钮
			      area: ['50%', '65%'],
			      content: "${WEB_PATH }/system/companysection/view/add.do?id="+menuId,
			      btn: ['确定','取消'],
			      yes: function(index, layero){
				      var body = layer.getChildFrame('body', index);
				      var iframeWin = window[layero.find('iframe')[0]['name']];
				      iframeWin.saveAddForm();
				  },
				  cancel: function(){
					  layer.closeAll();
				  }
			});
        });
        //加载编辑页面   
        $("#editMeun").click(function(){
        	if ("" == menuId) {
		                swal({
		                        title: "请选择要修改的组织机构",
		                        text: "请选中需要修改的组织机构，在使用修改操作。"
		                }); 
		             	return;
		    }
		    if ("1" == leavaId) {
		                swal({
		                        title: "提示",
		                        text: "顶级组织机构不能修改。"
		                }); 
		             	return;
		    }
		    layer.open({
			      type: 2,
			      title: '<span style="color: #ed5565">新增机构<span>',
			      shadeClose: false, 
			      shade: 0.3,
			      maxmin: false, //开启最大化最小化按钮
			      area: ['50%', '65%'],
			      content: "${WEB_PATH }/system/companysection/view/edit.do?id="+menuId,
			      btn: ['确定','取消'],
			      yes: function(index, layero){
				      var body = layer.getChildFrame('body', index);
				      var iframeWin = window[layero.find('iframe')[0]['name']];
				      iframeWin.saveEditForm();
				  },
				  cancel: function(){
					  layer.closeAll();
				  }
			});
        });
        
        //删除组织机构
	        $('#delMeun').click(function () {
	        	if ("" == menuId) {
		                swal({
		                        title: "请选择要删除的组织机构",
		                        text: "请选中需要删除的组织机构，在使用删除操作。"
		                }); 
		             	return;
		        }
		        
		        layer.confirm('<span style="color: red">您确定要删除该数据?</span>',{icon: 3, title:'系统提示',btn: ['确认','取消']},
	    		function(){
	        			$.ajax({
								 url: '${WEB_PATH }/system/companysection/remove.do?id=' + menuId,
								cache : false,
								type : 'POST',
								success : function(result) {
									var data = $.parseJSON(result);
									if(data.success == true){
										if(data.status!="1"){
											swal("删除成功！", "您已经永久删除了该组织机构。", "success")
											location.reload();
										}else{
											swal({
										        title: "",
										        text: data.msg,
										        type: "warning",
										        showCancelButton: true,
										        confirmButtonColor: "#DD6B55",
										        confirmButtonText: "是的，我要删除！",
										        cancelButtonText: "让我再考虑一下…",
										        closeOnConfirm: false,
										        closeOnCancel: false
										    },function(isConfirm){
										   		 if (isConfirm){
											   		 	$.ajax({
														 url: '${WEB_PATH }/system/companysection/remove.do?id=' + menuId+"&confirm=true",
															cache : false,
															type : 'POST',
															success : function(result) {
																var data = $.parseJSON(result);
																if(data.success == true){
																	swal("删除成功！", "您已经永久删除了该组织机构。", "success")
																	location.reload();
																}else{
																	swal("删除失败！", data.msg, "error")
																}
															},
															error: function(result) {
																swal("删除失败！", result.msg, "error")
															}
													});
										   		 	
										   		 }else {
										            swal("已取消", "您取消了删除操作！", "error")
										         }
										    });
										}
									}else{
										swal("删除失败！", data.msg, "error")
									}
								},
								error: function(result) {
									swal("删除失败！", result.msg, "error")
								}
						});
				});
			});
        
});
</script>
</body>

</html>